package com.analyzer.tool;

import java.io.IOException;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;

public abstract class Config
{
	private static Properties CONFIG = new Properties();
	private static String CONFIG_FILENAME = "config.properties";

	static {
		try { CONFIG.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(CONFIG_FILENAME));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String getString(String key)
	{
		return CONFIG.getProperty(key);
	}

	public static String getString(String key, String defaultValue)
	{
		String value = CONFIG.getProperty(key);
		if (StringUtils.isNotEmpty(value)) {
			value = defaultValue;
		}
		return value;
	}

	public static int getInt(String key, int defaultValue)
	{
		String temp = CONFIG.getProperty(key);
		if (temp == null) {
			return defaultValue;
		}
		return Integer.parseInt(temp);
	}

	public static int getInt(String key)
	{
		return getInt(key, 0);
	}

	public static long getLong(String key)
	{
		String temp = CONFIG.getProperty(key);
		return Long.parseLong(temp);
	}
}
